package mianshi.baidu;

import java.util.Scanner;

public class T1 {

    static int[] dx = {1, 0, 0, -1};
    static int[] dy = {0, 1, -1, 0};
    static int count = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[][] data = new int[n][n];
        int[][] res = new int[n * k][n * k];
        boolean[][] used = new boolean[n * k][n * k];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                data[i][j] = scanner.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {

                if (data[i][j] == 1) {
                    dfs(data, i, j, res, used, k);
                }


            }
        }

        for (int i = 0; i < res.length; i++) {
            for (int j = 0; j < res[0].length; j++) {
                System.out.print(res[i][j] + " ");

            }
            System.out.println();
        }

    }

    private static void dfs(int[][] data, int x, int y, int[][] res, boolean[][] used, int k) {
        if (x < 0 || x >= x + k || y < 0 || y >= y + k || used[x][y]) {
            return;
        }
        if (x==0) {
            x+=k;

        }else if (y==0) {
            y+=k;

        }else {

        }

        res[x][y] = 1;
        used[x][y] = true;
        dfs(data, x + 1, y, res, used, k);
        dfs(data, x - 1, y, res, used, k);
        dfs(data, x, y + 1, res, used, k);
        dfs(data, x, y - 1, res, used, k);
        dfs(data, x - 1, y - 1, res, used, k);
        dfs(data, x + 1, y + 1, res, used, k);
        dfs(data, x + 1, y - 1, res, used, k);
        dfs(data, x - 1, y + 1, res, used, k);
    }
}

